package com.shaoshaohuo.app.constant;

import android.support.v4.app.FragmentTransaction;

import com.alipay.sdk.Base64;
import com.shaoshaohuo.app.R;
import com.shaoshaohuo.app.net.HttpConfig;
import com.shaoshaohuo.app.utils.StringUtil;

import java.io.UnsupportedEncodingException;
import java.security.InvalidAlgorithmParameterException;
import java.security.InvalidKeyException;
import java.security.Key;
import java.security.NoSuchAlgorithmException;
import java.security.spec.InvalidKeySpecException;

import javax.crypto.BadPaddingException;
import javax.crypto.Cipher;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.NoSuchPaddingException;
import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.DESedeKeySpec;
import javax.crypto.spec.IvParameterSpec;

/**
 * @author linmu
 * @ClassName AppConfig
 * @Decription 工程配置
 * @2015-9-26 上午10:37:41dddd
 */
public class AppConfig {

    public static final boolean DEBUG = !(HttpConfig.serverEnvironment == HttpConfig.ServerEnvironmentEnum.ONLINE);
    private final static String DES = "DES";
    private static final String DES_IV = "20462016";
    private static final String DES_ENCODING = "utf-8";
    private static boolean isCarOwner = true;

    public static final String UMENG_APP_KEY = "56779f9f67e58eedec001c2a";

    /**
     * 解析Des加密后的手机
     *
     * @param key
     * @return
     */
    public static String getPhone(String data, String key) {
        if (data == null)
            return "";
//        byte[] newkey = Base64.decode(key.getBytes(), Base64.DEFAULT);
        if (StringUtil.isEmpty(key)) {
            return data;
        }

        Key deskey = null;
        try {
            key = "shaoshaowangluo727" + key;
            DESedeKeySpec spec = new DESedeKeySpec(key.getBytes());
            SecretKeyFactory keyfactory = null;
            keyfactory = SecretKeyFactory.getInstance("desede");
            deskey = keyfactory.generateSecret(spec);
            Cipher cipher = Cipher.getInstance("desede/CBC/PKCS5Padding");
            IvParameterSpec ips = new IvParameterSpec(DES_IV.getBytes());
            cipher.init(Cipher.DECRYPT_MODE, deskey, ips);
            byte[] decryptData = cipher.doFinal(Base64.decode(data));
            return new String(decryptData, DES_ENCODING);
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        } catch (InvalidKeyException e) {
            e.printStackTrace();
        } catch (InvalidKeySpecException e) {
            e.printStackTrace();
        } catch (NoSuchPaddingException e) {
            e.printStackTrace();
        } catch (InvalidAlgorithmParameterException e) {
            e.printStackTrace();
        } catch (BadPaddingException e) {
            e.printStackTrace();
        } catch (IllegalBlockSizeException e) {
            e.printStackTrace();
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }

        return "";
    }


    /**
     * 统一的fragment切换效果
     */
    public static final int FRAGMENT_TRANSITION = FragmentTransaction.TRANSIT_FRAGMENT_FADE;

    /**
     * 表示该过滤效果，禁用
     */
    public static final int FRAGMENT_NONE = -1;

    /**
     * 统一的fragment切换效果， 默认使用定制
     * 使用定制的动画效果。如果想使用系统自带效果。需要把 FRAGMENT_CUSTOM_TRANSITION_LEFT_OUT 和 FRAGMENT_CUSTOM_TRANSITION_RIGHT_IN ，设置为 FRAGMENT_NONE
     */
//    public static final int FRAGMENT_CUSTOM_TRANSITION_RIGHT_IN = R.anim.anim_right_in;
    public static final int FRAGMENT_CUSTOM_TRANSITION_RIGHT_OUT = R.anim.anim_right_out;
    public static final int FRAGMENT_CUSTOM_TRANSITION_RIGHT_IN = FRAGMENT_NONE;
    //    public static final int FRAGMENT_CUSTOM_TRANSITION_RIGHT_OUT = FRAGMENT_NONE;
    public static final int FRAGMENT_CUSTOM_TRANSITION_LEFT_IN = R.anim.anim_left_in;
    //    public static final int FRAGMENT_CUSTOM_TRANSITION_LEFT_OUT = R.anim.anim_left_out;
    public static final int FRAGMENT_CUSTOM_TRANSITION_LEFT_OUT = FRAGMENT_NONE;

    /**
     * 统一的fragment切换效果， 默认使用定制，使用于物流
     * 使用定制的动画效果。如果想使用系统自带效果。需要把 FRAGMENT_CUSTOM_TRANSITION_LEFT_OUT 和 FRAGMENT_CUSTOM_TRANSITION_RIGHT_IN ，设置为 FRAGMENT_NONE
     */
    public static final int FRAGMENT_CUSTOM_TRANSITION_RIGHT_IN_CAR = R.anim.anim_fragment_right_in;
    public static final int FRAGMENT_CUSTOM_TRANSITION_RIGHT_OUT_CAR = R.anim.anim_fragment_right_out;
    public static final int FRAGMENT_CUSTOM_TRANSITION_LEFT_IN_CAR = R.anim.anim_fragment_left_in;
    public static final int FRAGMENT_CUSTOM_TRANSITION_LEFT_OUT_CAR = R.anim.anim_fragment_left_out;


    public static final int FRAGMENT_CUSTOM_TRANSITION_FADE_IN = R.anim.custom_dialog_anim_show;
    public static final int FRAGMENT_CUSTOM_TRANSITION_FADE_OUT = R.anim.custom_dialog_anim_dismiss;


//    public static void setCarOwner(boolean isCar){
//    	isCarOwner = isCar;
//    }

    public static int getRoleId() {
//        return SharedPreferencesHelper.getInt(Field.USER_ROLE_ID, 0);
        return 3;
    }
}
